<template>
  <div class="flex items-center">
    <el-input v-model="value.refund_amount" placeholder="请输入" class="mr-[6px] w-[164px]" oninput="value=value.replace(/^\D*([0-9]\d*\.?\d{0,2})?.*$/, '$1')" @blur="amountChange">
      <template #append>{{ value.original_order_currency || "USD" }}</template>
    </el-input>
    <el-checkbox v-model="value.tax_included" label="含税金额" @change="includedChange" />
    <el-tooltip effect="dark" content="ebay后台订单上显示的金额是含税金额" placement="top">
      <span class="dk-iconfont icon-QuestionFilled"></span> 
    </el-tooltip>
  </div>
</template>

<script setup>
import { ElMessage } from "element-plus"
const props = defineProps({
  value: { type: Object, default: () => ({}) },
})
const amountChange = () => {
  if (Number(props.value.refund_amount) == 0) {
    props.value.refund_amount = 1
    return ElMessage.warning("退款金额不可为0")
  }

  if (props.value.platform_id == 1 && props.value.original_order_amount < Number(props.value.refundable_amount_tax)) {
    props.value.refund_amount = 1
    return ElMessage.warning("退款金额不能大于订单金额")
  }
  if (props.value.handleType == "updata") return
  if (props.value.tax_included) {
    if (props.value.refund_amount > props.value.refundable_amount_tax) {
      ElMessage.warning("退款金额不能大于订单剩余退款金额，订单可退金额为" + props.value.refundable_amount_tax)
      if (props.value.platform_id == 2 || props.value.platform_id == 67) return
      props.value.refund_amount = props.value.refundable_amount_tax
    }
  } else {
    if (props.value.refund_amount > props.value.refundable_amount) {
      ElMessage.warning("退款金额不能大于订单剩余退款金额，订单可退金额为" + props.value.refundable_amount)
      if (props.value.platform_id == 2 || props.value.platform_id == 67) return
      props.value.refund_amount = props.value.refundable_amount
    }
  }
}
const includedChange = (e) => {
  props.value.refund_amount = e ? props.value.refundable_amount_tax : props.value.refundable_amount
}
</script>
